% Genral setting window configuration
% June 2016
% Hamzeh Sadeghisorkhani

%% General Setting panel
h.panel(1)= uipanel(mainfig,'visible','on','Position',[.235 .15 .74 .8]);
set(h.panel(1),'BackgroundColor',panel_color)



%% Text boxes
%-------------------------------- Region
uicontrol(h.panel(1),'Style','text', 'String','Region',...
    'HorizontalAlignment','left','Fontweight','bold',...
    'Units','normalized','Position',[.01 .9 .4 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(1),'Style','text', 'String','Left Bottom Corner',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .84 .24 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(1),'Style','text', 'String','Latitude 1',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.33 .84 .15 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(1),'Style','text', 'String','Longitude 1',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.64 .84 .15 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(1),'Style','text', 'String','Right Top Corner',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .78 .24 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(1),'Style','text', 'String','Latitude 2',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.33 .78 .15 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(1),'Style','text', 'String','Longitude 2',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.64 .78 .15 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(1),'Style','text', 'String','Map File',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.09 .68 .2 .05],...
    'BackgroundColor',panel_color);


%-------------------------------- Data Management
uicontrol(h.panel(1),'Style','text', 'String','Data Management',...
    'HorizontalAlignment','left','Fontweight','bold',...
    'Units','normalized','Position',[.01 .52 .4 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(1),'Style','text', 'String','Data Folder',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .46 .24 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(1),'Style','text', 'String','Saving Folder',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .4 .24 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(1),'Style','text', 'String','Output File Format',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .3 .24 .05],...
    'BackgroundColor',panel_color);




%% Editable text 
%-------------------------------- Region
h2.lat1= uicontrol(h.panel(1),'Style','edit', 'String',params.lat1,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.46 .855 .1 .04],...
    'BackgroundColor','w');

h2.lon1= uicontrol(h.panel(1),'Style','edit', 'String',params.lon1,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.79 .855 .1 .04],...
    'BackgroundColor','w');


h2.lat2= uicontrol(h.panel(1),'Style','edit', 'String',params.lat2,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.46 .795 .1 .04],...
    'BackgroundColor','w');

h2.lon2= uicontrol(h.panel(1),'Style','edit', 'String',params.lon2,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.79 .795 .1 .04],...
    'BackgroundColor','w');


h2.map= uicontrol(h.panel(1),'Style','edit', 'String',params.map,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.22 .695 .6 .04],...
    'BackgroundColor','w');

h2.iconmap= uicontrol(h.panel(1),'Style','pushbutton', 'String','',...
    'Cdata',icons.file,'Tag','map',...
    'Units','normalized','Position',[.83 .695 .05 .04],...
    'callback',@folder_cbk);


%-------------------------------- Data Management
h2.data= uicontrol(h.panel(1),'Style','edit', 'String',params.data,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.22 .475 .6 .04],...
    'BackgroundColor','w');

h2.save= uicontrol(h.panel(1),'Style','edit', 'String',params.save,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.22 .415 .6 .04],...
    'BackgroundColor','w');


h2.icon(1)= uicontrol(h.panel(1),'Style','pushbutton', 'String','',...
    'Cdata',icons.folder,'Tag','data_folder',...
    'Units','normalized','Position',[.83 .475 .06 .04],...
    'callback',@folder_cbk);

h2.icon(2)= uicontrol(h.panel(1),'Style','pushbutton', 'String','',...
    'Cdata',icons.folder,'Tag','save_folder',...
    'Units','normalized','Position',[.83 .415 .06 .04],...
    'callback',@folder_cbk);


h2.radiobutton(5)= uibuttongroup(h.panel(1),'units','normalized','BackgroundColor',panel_color,...
    'bordertype','none','Position',[.24 .305 .5 .05]);

h2.radio(14) = uicontrol( h2.radiobutton(5), 'Style','Radio','String','.mat',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.1 0 .3 1],'HandleVisibility','off');
h2.radio(15) = uicontrol( h2.radiobutton(5), 'Style','Radio','String','txt',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.5 0 .3 1],'HandleVisibility','off');



%% Saving buttons

uicontrol(h.panel(1),'style','pushbutton', 'string','Default',...
    'ToolTipString','Load default setting','Tag','default1',...
    'units','normalized','position',[.1 .03 .18 .07], ...
    'callback',@default_cbk);

uicontrol(h.panel(1),'style','pushbutton', 'string','Latest',...
    'ToolTipString','Load latest setting','Tag','latest1',...
    'units','normalized','position',[.41 .03 .18 .07], ...
    'callback',@latest_cbk);

uicontrol(h.panel(1),'style','pushbutton', 'string','Save',...
    'ToolTipString','Save setting changes','Tag','save1',...
    'units','normalized','position',[.72 .03 .18 .07], ...
    'callback',@save_cbk);



%% Setting values
if strcmp(params.outputformat,'.mat')
    set (h2.radio(14),'value',1);
    set (h2.radio(15),'value',0);
elseif strcmp(params.outputformat,'txt')
    set (h2.radio(14),'value',0);
    set (h2.radio(15),'value',1);        
end



